package eventdisplay;

import processing.core.PApplet;
import processing.core.PVector;
import remixlab.proscene.*;

public class EventDisplayApplet extends PApplet {
	
	Scene scene;

	Cylinder module1, module2, hole1, hole2;
	VetoShield vShield;
	TrackData track;
	String[] listOfFiles;
        String[] listOfUrls;
        String fileListName = "http://www.soudan.umn.edu/eventDisplay/data/newlist.txt";
	String filename;
        TrackList tracklistobj;
	
	Letters let;

	PApplet parent;

	private int w, h;
	
	double x = 5;
        
	PVector xpos = new PVector(500, 0, 0);
	PVector ypos = new PVector(0, 500, 0);
	PVector zpos = new PVector(0, 0, 500);
	
	PVector origin = new PVector(0, 0, 0);

	int module1Col = color(255, 255, 255, 255);
	int module2Col = color(255, 255, 255, 255);
	int cntr1Col = color(120, 120, 120, 255);
	int cntr2Col = color(120, 120, 120, 255);
	int vShldCol1 = color(0, 0, 120, 255);
	int vShldCol2 = color(0, 0, 120, 255);
	int vShldCol3 = color(0, 0, 120, 255);
	
	int canadaPointY, canadaPointX, fermilabPointY, fermilabPointX;

	boolean isModule1Drawn = true;
	boolean isModule2Drawn = true;
	boolean isHoleDrawn = true;
	boolean isvShld1Drawn = true;
	boolean isvShld2Drawn = true;
	boolean isvShld3Drawn = true;
	boolean isTrackDrawn = true;
	boolean isOpen;
	boolean isInfoDrawn;

	int vertCol = 255;
	int spCol = 0;

	int len = 0;
	int Fn = 0;

	int Fs = 1;

	int inc = 1;
	int tracelength;

	public EventDisplayApplet(int w, int h) {
		this.w = w;
		this.h = h;
                tracklistobj = new TrackList(this,fileListName);
                filename = tracklistobj.listOfUrls[0];
	}

	public void setup() {

		size(w, h, P3D);
		scene = new Scene(this);
		smooth();
		// frameRate(30);
		//scene.drawGrid(1000);
		scene.setAxisIsDrawn(false);
		scene.setGridIsDrawn(false);
		scene.disableKeyboardHandling();
                //scene.setShortcut('f', Scene.KeyboardAction.DRAW_FRAME_SELECTION_HINT);
		scene.camera().setType(Camera.Type.ORTHOGRAPHIC);
		scene.camera().setStandardZNear(0);
		scene.camera().setPosition(zpos);


		module1 = new Cylinder(this, x*40, 8, x*5.75, x*(147.8+5.75) );
		module2 = new Cylinder(this, x*40, 8, -x*5.75, -x*(141+5.75) );
		hole1 = new Cylinder(this, x*2.5, 8, x*5.75, x*(147.8+5.75) );
		hole2 = new Cylinder(this, x*2.5, 8, -x*5.75, -x*(141+5.75) );
		vShield = new VetoShield(this, x*(147.8+5.75),-x*(141+5.75) );
		track = new TrackData(this, filename);
		let = new Letters(this,2,10);

		tracelength = track.particleTrace.length;

		Fn = 0;
		
		

	}

	public void draw() {

		background(0);

		pushMatrix();

		if (isModule1Drawn) {
			module1.drawCylinder(module1Col);
		}
		if (isModule2Drawn) {
			module2.drawCylinder(module2Col);
		}
		if (isHoleDrawn & isModule1Drawn) {
			hole1.drawCylinder(cntr1Col);
		}
		if (isHoleDrawn & isModule2Drawn) {
			hole2.drawCylinder(cntr2Col);
		}
		if (isvShld1Drawn) {
			vShield.drawVetoShield1(vShldCol1);
		}
		if (isvShld2Drawn) {
			vShield.drawVetoShield2(vShldCol2);
		}
		if (isvShld3Drawn) {
			vShield.drawVetoShield3(vShldCol3);
		}
		
		if (isInfoDrawn) {
			//textMode(SCREEN);
			translate((float) -12.5, 25, (float) (5*(147.8+5.75)));
			let.drawLetter('C');
			translate((float) 12.5, -25, (float) (-5*(147.8+5.75)));
			translate((float) -12.5, 25, (float) (-5*(141+5.75)));
			let.drawLetter('F');
			translate((float) 12.5, -25, (float) (5*(141+5.75)));
			}

		if ((len < tracelength) && (Fn % Fs == 0)) {
			len = len + inc;
		}
		
		translate(0, 0, (float) (-5*(141+5.75)));

		if (track != null & isTrackDrawn) {
			track.drawVertSphereAnim(len);
		}
		
		popMatrix();

		Fn++;
	}


}